package com.runda.partypolicy.app.page.activity.login;

import android.content.Intent;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.runda.partypolicy.R;
import com.runda.partypolicy.app.base.BaseActivity;
import com.runda.partypolicy.app.page.viewmodel.ViewModel_Splash;


import java.util.concurrent.TimeUnit;

import androidx.lifecycle.ViewModelProviders;
import butterknife.BindView;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class Activity_Splash extends BaseActivity<ViewModel_Splash> {

    @BindView(R.id.iv_welcome)
    ImageView ivWelcome;
    private Disposable disposable;
    private long count = 4;


    @Override
    public int getLayout() {
        return R.layout.activity_splash;
    }

    @Override
    public ViewModel_Splash initViewModel() {
        return ViewModelProviders.of(this, getViewModelFactory()).get(ViewModel_Splash.class);
    }

    @Override
    public void initEvents() {

    }

    @Override
    public void start() {


        disposable = Observable.interval(0, 1, TimeUnit.SECONDS)
                .subscribeOn(AndroidSchedulers.mainThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) throws Exception {

                        Glide.with(Activity_Splash.this)
                                .asGif()
                                .load(R.drawable.welcome).into(ivWelcome);


                        count--;
                        if (count == 0) {
                            Intent intent = new Intent(Activity_Splash.this, Activity_Login.class);
                            Activity_Splash.this.startActivity(intent);
                            disposable.dispose();
                            finish();
                        }

                    }
                });

    }

    @Override
    public void initNotSignEvent() {

    }

    @Override
    public void initNoNetworkEvent() {

    }

    @Override
    public void initShowMessageEvent() {

    }

    @Override
    public void initTokenOverTimeEvent() {

    }

    @Override
    public void initShowOrDismissWaitingEvent() {

    }

    @Override
    public void initStateLayoutEvent() {

    }

    @Override
    protected void onStop() {
        super.onStop();

        if (disposable != null && !disposable.isDisposed()) {
            disposable.dispose();

        }
    }
}
